<template>

    <div class="login_contatiner">
        <div id="login">
            <vue-particles
                    class="login-bg"
                    color="#39AFFD"
                    :particleOpacity="0.7"
                    :particlesNumber="100"
                    shapeType="circle"
                    :particleSize="4"
                    linesColor="#8DD1FE"
                    :linesWidth="1"
                    :lineLinked="true"
                    :lineOpacity="0.4"
                    :linesDistance="150"
                    :moveSpeed="3"
                    :hoverEffect="true"
                    hoverMode="grab"
                    :clickEffect="true"
                    clickMode="push"
            >
            </vue-particles>
        </div>
        <div class="login_box">
            <div class="avatar_box">
                <img src="../assets/logo.png" alt="">
            </div>
            <el-form  ref="loginForm" label-width="0px" class="login_form" :model="loginForm" :rules="loginRules">
                <!-- 账号-->
                <el-form-item prop="account">
                    <el-input  prefix-icon="el-icon-user-solid" v-model="loginForm.account"></el-input>
                </el-form-item>
                <!-- 密码-->
                <el-form-item prop="password">
                    <el-input  prefix-icon="el-icon-goods" v-model="loginForm.password" type="password"></el-input>
                </el-form-item>
                <el-form-item class="btns">
                    <el-button type="prinary" @click="login">登录</el-button>
                    <el-button type="info" @click="resetLoginForm">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
    export default {
        name: "Login",
        data(){
            return{
                loginForm:{
                    account:'189000105',
                    password:'123456'
                },
                loginRules:{
                    account:[
                        { required: true, message: '请输入登录账号', trigger: 'blur' }
                    ],
                    password:[
                        { required: true, message: '请输入登录密码', trigger: 'blur' }
                    ],
                }
            }
        },
        methods:{
            resetLoginForm(){
                this.$refs.loginForm.resetFields()
            },
            login(){
                this.$refs.loginForm.validate(async valid => {
                    if(!valid)return;
                   const {data: res} = await this.$http.post('Login/Logins', this.loginForm);
                   if(res.code !== 200){return this.$message.error(res.message);}else {
                       this.$message.success(res.message)
                       window.sessionStorage.setItem("token",res.data.token);
                       window.sessionStorage.setItem('id',res.data.id)
                       window.sessionStorage.setItem('name',res.data.name)
                       this.$router.push("/home");
                   }
                })
            }
        }
    }
</script>

<style lang="less" scoped>
.login_contatiner{
    background-color: antiquewhite;
    height: 100%;
}
    .login_box{
        width: 450px;
        height: 300px;
        background-color: azure;
        border-radius: 3px;
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%,-50%);
    }
    .avatar_box{
        height: 130px;
        width: 130px;
        border: 1px solid #eeeeee;
        border-radius: 50%;
        padding: 10px ;
        box-shadow: 0 0 10px #dddddd;
        position: absolute;
        left: 50%;
        transform: translate(-50%,-50%);
        background-color: azure;
        img{
            width: 100%;
            height: 100%;
            border-radius: 50%;
            background-color: #eeeeee;
        }
    }
    .btns{
        display: flex;
        justify-content: flex-end;
    }
    .login_form{
        position: absolute;
        bottom: 0;
        width: 100%;
        padding:0 20px;
        box-sizing: border-box;
    }
.login{
    width: 100%;
    height: 100%;
    //color: #cccccc;
    /*如果想做背景图片 可以给标签一个class 直接添加背景图*/
    //position: relative;
}
// 如果屎全屏展示
.login-bg{
    width: 100%;
    height: 100%;
    background: #3E3E3E;
}

</style>